package ciyuanwutuobang.threadagainstdeath;

import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Timer;

/**
 * @author 150149
 */
public final class ThreadAgainstDeath extends JavaPlugin {

    public static final String MSG_PREFIX = "§8[ §cThreadAgainstDeath §8]§7 ";

    private Timer threadChecker;

    @Override
    public void onEnable() {
        new TPSCheck(this);
        if (Bukkit.isPrimaryThread()) {
            threadChecker = new Timer();
            threadChecker.scheduleAtFixedRate(new MainThreadCheck(), 0L, 500L);
        } else {
            logInfo("线程防死无法开启");
        }
    }

    @Override
    public void onDisable() {
        threadChecker.cancel();
        logInfo("线程防死已关闭");
        // Plugin shutdown logic
    }

    public static void logInfo(String msg) {
        Bukkit.getConsoleSender().sendMessage(MSG_PREFIX + msg);
    }
}
